<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>喇叭数</title>
    <script>
      //获取输入值的阶乘
      function getFactorialNum(num) {
        var result = 1;
        var i = 1;
        while (i <= num) {
          result *= i;
          i++;
        }
        // console.log(num + "的阶乘等于" + result);
        return result;
      }
      //获取喇叭数
      //求一个三位数，叫做“喇叭花数”，该三位数等与其每位数字的阶乘之和
      function outputAllFlowerNum() {
        // 输出100~999的所有喇叭花数
        var i = 100; //初始变量
        while (i <= 999) {
          var ge = i % 10,
            shi = parseInt(i / 10) % 10;
          bai = parseInt(i / 100);
          var sum = getFactorialNum(ge) + getFactorialNum(shi) + getFactorialNum(bai);
          if (i === sum) {
            console.log("100~999的喇叭数有：" + i); //100~999的喇叭数有：145
          }
          i++;
        }
      }
      outputAllFlowerNum();
    </script>
  </head>
  <body></body>
</html>
